Remove newline characters from a fileΒΆ
Remove newline characters from a file.
def remove_newlines(fname):
text = open(fname).readlines()
return [line.rstrip('\n') for line in text]
# test
print(remove_newlines("test.txt"))
Output:
['Welcome to w3resource.com.', 'Append this text.Append this text.Append this text.',
'Append this text.', 'Append this text.', 'Append this text.', 'Append this text.']